Skip to content

[CompilerPlugin] Remove Foundation dependency #2598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Apr 22, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 11, 2024

  • read(2) / write(2) instead of Foundation.FileHandle
  • Implement its own JSON encoder/decoder

rdar://126714084

@bnbarham
Copy link
Contributor

@swift-ci Please test Windows

@rintaro rintaro force-pushed the macros-jsoncoder branch 2 times, most recently from 38e6d49 to 7fbf536 Compare April 12, 2024 17:34
@rintaro
Copy link
Member Author

rintaro commented Apr 12, 2024

swiftlang/swift#73010
@swift-ci Please test Windows

@rintaro rintaro marked this pull request as ready for review April 19, 2024 13:56
@rintaro rintaro requested a review from hamishknight April 19, 2024 14:20
mutating func closeCollection(handle: Int) {
// 'handle': descriptor index.
// 'handle+1': counter index.
mapData[handle + 1] = mapData.count - handle - 2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to - 2 here. Only usage (i.e. JSONMapValue.mapSize) is doing + 2. Let's just store the mapSize value, so mapSize can return the stored value as-is.

rintaro added 3 commits April 19, 2024 19:06
* typo
* Remove unnecessary withExtendedLifetime()
* remove JSONObject.subscript(_:) as it's not O(1)
* Use 'LosslessStringConvertible'
* Don't use UTF8 decoder for decoding escaped strings
* Only memcmp ASCII non-escaped strings
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. Don’t be distracted by the truckload of comments that I’m leaving here. I think most are nitpicky, just a few correctness questions.

@rintaro
Copy link
Member Author

rintaro commented Apr 21, 2024

@swift-ci Please test

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Apr 21, 2024

@swift-ci Please test

@rintaro rintaro force-pushed the macros-jsoncoder branch 3 times, most recently from e02a7a0 to a684b3b Compare April 22, 2024 18:56
guard case .array(var arr) = backing else {
preconditionFailure()
}
backing = .null // Ensure 'err' uniquely referenced.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick 😉

Suggested change
backing = .null // Ensure 'err' uniquely referenced.
backing = .null // Ensure 'arr' uniquely referenced.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only open discussion is why we needed to define compareMemory for SyntaxText but can unconditionally use memcmp here: #2598 (comment)

rintaro added 4 commits April 22, 2024 12:05
Use 'for' look instead of 'while cursor != end { cursor += 1 }'
The source JSON buffer is not guaranteed to be null terminated. If a
number is at top-level, 'strtod'/'strtof' tries to read past the buffer
which is not great
Avoid possible module name collision
@rintaro
Copy link
Member Author

rintaro commented Apr 22, 2024

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Apr 22, 2024

@swift-ci Please test Windows

@rintaro
Copy link
Member Author

rintaro commented Apr 22, 2024

@swift-ci Please test Windows

@rintaro rintaro enabled auto-merge April 22, 2024 20:12
@rintaro rintaro merged commit 462e954 into swiftlang:main Apr 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants